import pandas as pd
import json  # 新增：用于 JSON 格式化

data = pd.read_csv('../../file/图书信息表.csv')
books = []

for _, row in data.iterrows():
    book = {
        "f_id": row['f_id'],
        "s_id": row['s_id'],
        "t_id": row['t_id'],
        "title": row['title'],
        "author": row['author'],
        "cover": row['cover'],
    }
    books.append(book)

# 将列表转换为 JSON 字符串并写入文件
with open('book.json', 'w', encoding='utf_8_sig') as f:
    json.dump(books, f, ensure_ascii=False, indent=4)  # 格式化输出